//
//  SYProgressHUD.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/20.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "SYProgressHUD.h"


@interface SYProgressHUD()

@property (nonatomic , strong) MBProgressHUD *hud;

@end

@implementation SYProgressHUD

static SYProgressHUD *_instance;

+ (instancetype)allocWithZone:(struct _NSZone *)zone
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [super allocWithZone:zone];
    });
    return _instance;
}

+ (instancetype)sharedInstance
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc] init];
    });
    return _instance;
}

- (id)copyWithZone:(NSZone *)zone
{
    return _instance;
}

-(void)showMBHudWithSting:(NSString *)string
{
    _hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    //提示框的背景色,要想改变提示方框的背景色，只有这样设置才会生效
    _hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    _hud.bezelView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7];
    
    //    _hud.backgroundView.
    //消失时的动画模式
    _hud.animationType = MBProgressHUDAnimationZoom;
    //提示模式
    _hud.mode = MBProgressHUDModeIndeterminate;
    //填充内容颜色，包括指示器的颜色NumberColor(62, 89, 167)
    _hud.contentColor = [UIColor whiteColor];
    //    _hud.contentColor = [UIColor whiteColor];
    _hud.label.text = string;
    _hud.label.textColor = [UIColor whiteColor];
}
-(void)showMBHudWithString:(NSString *)string SuperView:(UIView *)superView
{
    _hud = [MBProgressHUD showHUDAddedTo:superView animated:YES];
    //提示框的背景色,要想改变提示方框的背景色，只有这样设置才会生效
    _hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    _hud.bezelView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7];
    //消失时的动画模式
    _hud.animationType = MBProgressHUDAnimationZoom;
    //提示模式
    _hud.mode = MBProgressHUDModeIndeterminate;
    //填充内容颜色，包括指示器的颜色NumberColor(62, 89, 167)
    _hud.contentColor = [UIColor whiteColor];
    //    _hud.contentColor = [UIColor whiteColor];
    _hud.label.text = string;
    _hud.label.textColor = [UIColor whiteColor];
}
-(void)showMBHudOnlyLoading
{
    _hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    //提示框的背景色,要想改变提示方框的背景色，只有这样设置才会生效
    _hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    _hud.bezelView.backgroundColor = [UIColor clearColor];
    
    //    _hud.backgroundView.
    //消失时的动画模式
    _hud.animationType = MBProgressHUDAnimationZoom;
    //提示模式
    _hud.mode = MBProgressHUDModeIndeterminate;
    //填充内容颜色，包括指示器的颜色
//        _hud.contentColor = NumberColor(62, 89, 167);
    _hud.contentColor = zhidainMainColor;
}


-(void)showMBHudBackViewLoading
{
    _hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    _hud.bezelView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.8];
    
    _hud.animationType = MBProgressHUDAnimationZoom;
    //提示模式
    _hud.mode = MBProgressHUDModeIndeterminate;
    //填充内容颜色，包括指示器的颜色
    _hud.contentColor = [UIColor whiteColor];
}

-(void)showSVHudBackViewTextLoadingWithText:(NSString *)text
{
    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeNative];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
    [SVProgressHUD showWithStatus:text];
    
}

-(void)showSVOnlytextWithText:(NSString *)text
{
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD showImage:[UIImage imageNamed:@""] status:text];
}

-(void)showSVErrorWithImageName:(NSString *)imageName andText:(NSString *)text
{
    if (imageName.length) {
        UIImage *image = [UIImage imageNamed:imageName];
        [SVProgressHUD showImage:image status:text];
    }else{
        [SVProgressHUD showErrorWithStatus:text];
    }
}
-(void)showSVSuccessWithImageName:(NSString *)imageName andText:(NSString *)text
{
    if (imageName.length) {
        UIImage *image = [UIImage imageNamed:imageName];
        [SVProgressHUD showImage:image status:text];
    }else{
        [SVProgressHUD showSuccessWithStatus:text];
    }
}
-(void)dismissMBWithTime:(NSInteger)time
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [_hud hideAnimated:YES];
    });
}

-(void)dismissSVWithTime:(NSInteger)time
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
    });
}

- (void)showSVWithText:(NSString *)string afterDelay:(NSInteger)time
{
    [self showSVOnlytextWithText:string];
    [self dismissSVWithTime:time];
}



@end
